package zz.champion_contest07;

public class Q2_Business {
	//商户添加商品的方法
	public void put(Q2_Commodity commodity){
		if(Q2_Shop.hashMap.containsKey(commodity.getName()+commodity.getBrand())){
			Q2_Shop.hashMap.get(commodity).setNum(Q2_Shop.hashMap.get(commodity).getNum()+commodity.getNum());
		}else{
			Q2_Shop.hashMap.put(commodity.getName()+commodity.getBrand(), commodity);
		}
	}
	//商户找钱的方法
	public int cashier(Q2_Commodity commodity,int num,int money){
		int result=money;
		if(Q2_Shop.hashMap.containsKey(commodity.getName()+commodity.getBrand())){
			if(Q2_Shop.hashMap.get(commodity).getNum()>=num){
				if(money>=num*Q2_Shop.hashMap.get(commodity).getPrice()){
					Q2_Shop.hashMap.get(commodity).setNum(Q2_Shop.hashMap.get(commodity).getNum()-num);
					result=money-num*Q2_Shop.hashMap.get(commodity).getPrice();
				}else{
					System.out.println("交易失败");
				}
			}else{
				System.out.println("交易失败");
			}
		}else{
			System.out.println("交易失败");
		}
		return result;
	}
	//商户调整商品价格的方法
	public void setPrice(Q2_Commodity commodity,int price){
		if(Q2_Shop.hashMap.containsKey(commodity.getName()+commodity.getBrand())){
			Q2_Shop.hashMap.get(commodity.getName()+commodity.getBrand()).setPrice(price);
		}
	}
}
